﻿using System;
using System.Linq;
using NHibernate;
using NHibernate.Linq;

namespace Salary.Domain.Repository
{
    public class NhRepository<T> : IRepository<T> where T : Entity
    {
	    private readonly ISessionFactory _sessionFactory;

	    public NhRepository(ISessionFactory sessionFactory)
	    {
		    _sessionFactory = sessionFactory;
	    }

	    protected ISession Session
        {
            get { return _sessionFactory.GetCurrentSession(); }
        }

        public T Get(Guid id)
        {
            return Session.Get<T>(id);
        }

        public void Add(T entity)
        {
            Session.Save(entity);
        }

        public IQueryable<T> AsQueryable()
        {
            return Session.Query<T>();
        }

    }
}